package com.euond.accv.gateway.utils;

import com.euond.common.util.security.Md5Utils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author: QiangLiu
 * @create: 2017-11-22 下午6:44
 * @version: 1.0
 **/
public class TokenUtils {

    /**
     * 生成令牌
     * @param devId 开发者Id
     * @param devPassword 开发者密码
     * @return
     */
    public static String createToken(String devId, String devPassword, Date createDate,String deviceNo){
        long currentDate = System.currentTimeMillis();
        long randomNumber = RandomUtils.nextLong(1,10000000);

        String str = "";
        if(StringUtils.isNotBlank(deviceNo)){
            str = devId + devPassword + currentDate + randomNumber + deviceNo + createDate.toString();
        }else{
            str = devId + devPassword + currentDate + randomNumber + createDate.toString();
        }

        String accessToken = Md5Utils.hash(str);
        return accessToken;
    }

}
